package com.example.rbacmanage.util;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;


public class DoubleConverter implements Converter<Double> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Double.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.NUMBER;
    }

    @Override
    public Double convertToJavaData(ReadConverterContext<?> context){
        if (context.getReadCellData().getNumberValue() != null){
            return context.getReadCellData().getNumberValue().doubleValue();
        }
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Double> context) throws Exception {
        return Converter.super.convertToExcelData(context);
    }
}
